
<template>
  <page-header-wrapper>
    <a-card class="table-card">
      <GzSearchForm :searchFunc="searchFunc" :resetFunc="() => { searchData = {} }" searchConditionNum="6">
        <a-form-item class="table-search-item" label="月份筛选">
          <a-date-picker v-model:value="searchData['statDate']" picker="month" value-format="YYYY-MM" placeholder="统计月份" style="width:100%" />
        </a-form-item>
      </GzSearchForm>
      <!-- 列表渲染 -->
      <GzTable
        ref="infoTableRef"
        :init-data="true"
        :req-table-data-func="reqTableDataFunc"
        :table-columns="tableColumns"
        :search-data="searchData"
      >
        <template #topBtnSlot>
          <a-button
            v-if="$access('ENT_DATA_REPORT_SCORE_USE_ACTION')"
            type="primary"
            :disabled="exportShow"
            :loading="loading"
            @click="exportDataReports"
          >
            <template #icon>
              <ArrowUpOutlined />
            </template>
            导出
          </a-button>
        </template>
      </GzTable>
    </a-card>
  </page-header-wrapper>
</template>
  
  <script lang="ts" setup>
  import {$apiGoodsUseList,$apiGoodsUseExport} from '@/api/dataReports/goodsUse/index'
  import { ref, reactive,getCurrentInstance } from 'vue'
const { $infoBox, $access } = getCurrentInstance()!.appContext.config.globalProperties
  
  const infoTableRef = ref()
 
  const loading = ref(false)
  let tableColumns = reactive([
    { key: 'agentName', title: '单位', dataIndex: 'agentName', fixed: 'left' },
    { key: 'totalSyncScoreNum', title: '旧平台迁移福分', dataIndex: 'totalSyncScoreNum' },
    { key: 'monthAddScoreNum', title: ' 月新平台生成福分', dataIndex: 'monthAddScoreNum' },
    { key: 'monthAddBaifuScoreNum', title: '月百福进门生成福分', dataIndex: 'monthAddBaifuScoreNum' },
    { key: 'monthExchangeCouponScoreNum', title: '月福分兑换福券消耗积分情况', dataIndex: 'monthExchangeCouponScoreNum' },
    { key: 'monthConsumeCouponYuan', title: '月福券核销情况', dataIndex: 'monthConsumeCouponYuan' },
  ])
  const searchData: any = ref({})
  const exportShow = ref(true)
  // 请求table接口数据
  function reqTableDataFunc(params: any) {
   
    return new Promise((resolve, reject) => {
      $apiGoodsUseList({ ...params})
        .then((res: any) => {
          if(res.records.length === 0) {
            exportShow.value = true
          } else {
            exportShow.value = false
          }            
          resolve(res)
        })
        .catch((err: any) => {
          reject(err)
        })
    })
  }

  const exportDataReports = () =>{
    loading.value = true
    $apiGoodsUseExport({statDate:searchData.value.statDate}).then(res=>{
      loading.value = false
       $infoBox.message.success('导出成功')
    }).catch(()=>{
      loading.value = false
    })
  }

  // 搜索
  function searchFunc() {
    infoTableRef.value.refTable(true)
  }
  </script>